// @algorithm @lc id=2005 lang=cpp 
// @title check-if-all-the-integers-in-a-range-are-covered


// #define print(...)
// @test([[1,2],[3,4],[5,6]],2,5)=true
// @test([[1,10],[10,20]],21,21)=false
// @test([[1,50]],1,50)=true
// @test([[50,50]], 1, 1)=false
class Solution {
public:
bool isCovered(vector<vector<int>>& ranges, int left, int right) {
    // 差分数组
    vector<int> diff(52, 0);
    for(auto & r : ranges){
        diff[r[0]]++;   // 开始覆盖+1
        diff[r[1]+1]--; // 不再覆盖-1
    }
    // 前缀和
    int i=0;
    while(++i<left) diff[i] += diff[i-1];
    while(i++<=right)
        if(0 >=(diff[i-1] += diff[i-2]))
            return false;
    return true;
}
};